var params = '&semesterid=';
var semesterId = "";
var semesterUrl = "/query/queryAllSemester"
var accessUrl = "/query/dormTCheckDormYRecorddata";
var toDetailUrl = "";

window.onload = function() {

	accessMethodsemester(WEB_URL_PREFIX + semesterUrl, params, 'POST', 'json');

}

function gradeChange() {

	var objS = document.getElementById("listsemester");
	semesterId = objS.options[objS.selectedIndex].value;
	params = '&semesterid=';
	params += semesterId;
	accessMethod(WEB_URL_PREFIX + accessUrl, params, 'POST', 'json');
}

function printHtml(d) {
	var _html = appendBody_1(d.hlist);

	return _html;
}

function appendBody_1(data) {
	toDetailUrl = "/query/dormTCheckDormYCDRecord?semesterid=" + semesterId
			+ "&classid=";
	var _html = '';
	for (var i = 0; i < data.length; i++) {
		var tr = '<tr class="odd gradeX">';
		if (i % 2 == 0)
			tr = '<tr class="even gradeA">';
		_html += tr + '<td>' + (i + 1) + '</td>' 
				+ '<td>' + data[i].className+ '</td>' 
				+ '<td>' + data[i].vanishnum + '</td>' 
				+ '<td>'+ data[i].leavenum + '</td>' 
				+ '<td>' + data[i].notcheck+ '</td>' 
				+ '<td><a href="' + WEB_URL_PREFIX + toDetailUrl+ data[i].classid + '">详情</td>' 
				+ '</tr>';
	}
	return _html;
}
function printHtmlsemester(d) {
	var _html = '';

	for (var i = 0; i < d.length; i++) {
		_html += '<option value=' + d[i].id + '>' + d[i].name + '</option>';
	}
	return _html;
}

function accessMethod(url, params, type, dataType) {
	$.ajax({
		url : url,
		data : params,
		type : type,
		dataType : dataType,
		success : function(data) {
			$('#dataTables-example').DataTable().destroy();
			$("#tbody").empty();
			$("#tbody").append(printHtml(data));
			$("#tbody").show();

//			$('#dataTables-example').DataTable().clear();
			$('#dataTables-example').DataTable({
				language : {
					"sProcessing" : "处理中...",
					"sLengthMenu" : "显示 _MENU_ 项结果",
					"sZeroRecords" : "没有匹配结果",
					"sInfo" : "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
					"sInfoEmpty" : "显示第 0 至 0 项结果，共 0 项",
					"sInfoFiltered" : "(由 _MAX_ 项结果过滤)",
					"sInfoPostFix" : "",
					"sSearch" : "搜索:",
					"sUrl" : "",
					"sEmptyTable" : "表中数据为空",
					"sLoadingRecords" : "载入中...",
					"sInfoThousands" : ",",
					"oPaginate" : {
						"sFirst" : "首页",
						"sPrevious" : "上页",
						"sNext" : "下页",
						"sLast" : "末页"
					},
					"oAria" : {
						"sSortAscending" : ": 以升序排列此列",
						"sSortDescending" : ": 以降序排列此列"
					}
				},
				"lengthChange" : false,
				"paging" : false,
				"info" : false

			});

		},
		error : function(data) {
			debugger;
		}

	});
}

function accessMethodsemester(url, params, type, dataType) {
	$.ajax({
		url : url,
		data : params,
		type : type,
		dataType : dataType,
		success : function(data) {

			$("#listsemester").empty();
			$("#listsemester").append(printHtmlsemester(data.slist))
			$("#listsemester").show();
			semesterId = data.slist[0].id;
			params += semesterId;
			accessMethod(WEB_URL_PREFIX + accessUrl, params, 'POST', 'json');
		},
		error : function(data) {

		}

	});
}